/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditarArtista.java
 *
 * Created on 29/10/2011, 19:02:41
 */

package br.com.beethoven.ui;

import br.com.beethoven.exception.BDException;
import br.com.beethoven.model.entidade.vo.BandaVO;
import br.com.beethoven.model.fachada.IGerenciarBandaFacade;
import br.com.beethoven.model.fachada.impl.GerenciarBandaFacade;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author Jusabe
 */
public class EditarArtista extends javax.swing.JFrame {
    public BandaVO bandaVO = new BandaVO();
    public IGerenciarBandaFacade fachadaBanda;
    /** Creates new form EditarArtista */
    public EditarArtista() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        nomeEditarArtista = new javax.swing.JTextField();
        scrollEditarArtista = new javax.swing.JScrollPane();
        descricaoEditarArtista = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Nome");

        jLabel2.setText("Descrição");

        descricaoEditarArtista.setColumns(20);
        descricaoEditarArtista.setRows(5);
        scrollEditarArtista.setViewportView(descricaoEditarArtista);

        jButton1.setText("Salvar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cancelar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(58, 58, 58)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(nomeEditarArtista)
                            .addComponent(scrollEditarArtista)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(83, 83, 83)
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2)))
                .addContainerGap(126, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nomeEditarArtista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(scrollEditarArtista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(111, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        fachadaBanda = new GerenciarBandaFacade();
        try {
            bandaVO.setNome(this.nomeEditarArtista.getText());
            bandaVO.setDescricao(this.descricaoEditarArtista.getText());
            System.out.println(this.bandaVO.getId());
            System.out.println(this.bandaVO.getNome());
            System.out.println(this.bandaVO.getDescricao());
            fachadaBanda.editar(this.bandaVO);
            ArtistaListar artistaListar = new ArtistaListar();
            artistaListar.setVisible(true);
            this.dispose();
        } catch (BDException ex) {
            Logger.getLogger(EditarArtista.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        ArtistaListar artistaListar = new ArtistaListar();
        artistaListar.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EditarArtista().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea descricaoEditarArtista;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField nomeEditarArtista;
    private javax.swing.JScrollPane scrollEditarArtista;
    // End of variables declaration//GEN-END:variables

    void preencherEditarArtistaEditar(BandaVO _bandaVO) {
        this.bandaVO = _bandaVO;
        
        this.nomeEditarArtista.setText(_bandaVO.getNome());
        this.descricaoEditarArtista.setText(_bandaVO.getDescricao());
    }
    // End of variables declaration     
}
